# 啊哈！算法 第4章 第2节
# 创建地图
map = [[0 for i in range(5)] for j in range(6)]
for i in range(5):
    map[0][i] = 1
for j in range(6):
    map[j][0] = 1
map[1][1] = 1
map[1][3] = 1
map[3][3] = 1
map[4][2] = 1
map[5][4] = 1

# 位移数组 右 下 左 上
walk = [[1, 0], [0, 1], [-1, 0], [0, -1]]

# 搜索地图，需要记录下当前位置和步数
aim = [4,3]
min_step = float('inf')
step = 0
result = False

row =[[1, 1, 0]]
for x, y, step in row:
    if x == 3 and y == 4:
        print(step)
        print(map)
        break
    for k in range(4):
        new_x = x + walk[k][0]
        new_y = y + walk[k][1]
        if new_x < 5 and new_y < 6:
            if map[new_y][new_x] == 0:
                map[new_y][new_x] = step + 1
                s = step + 1
                row.append([new_x, new_y, s])

